package com.vision.mapper;

import com.vision.pojo.entity.UserCollect;
import com.vision.pojo.vo.CollectContentVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserCollectMapper {
    /**
     * 添加收藏视频
     * @param userId 用户id
     * @param videoId 视频id
     */
    @Insert("insert into vs_user_collect (user_id,video_id,update_time) values (#{userId},#{videoId},now())")
    void insert(Integer userId, Integer videoId);

    /**
     * 删除当前用户收藏的视频
     * @param videoId 视频id
     */
    @Delete("delete from vs_user_collect where video_id = #{videoId}")
    void deleteCollectByVideoId(Integer videoId);

    /**
     * 取消收藏视频
     * @param userId 用户id
     * @param videoId 视频id
     */
    @Delete("delete from vs_user_collect where user_id = #{userId} and video_id = #{videoId}")
    void cancelCollect(Integer userId, Integer videoId);

    /**
     * 查询当前用户收藏的视频
     * @param userId 用户id
     * @return 收藏视频列表
     */
    List<CollectContentVO> selectCollectVideoForPage(Integer userId);

/**
     * 查询当前用户收藏的视频数量
     * @param videoId 视频id
     * @return 收藏数量
     */
    @Select("select count(*) from vs_user_collect where video_id = #{videoId}")
    Integer selectCountByVideoId(Integer videoId);

    /**
     * 查询当前用户是否收藏了视频
     * @param userId 用户id
     * @param videoId 视频id
     * @return 收藏视频
     */
    @Select("select * from vs_user_collect where user_id = #{userId} and video_id = #{videoId}")
    UserCollect selectByUserIdAndVideoId(Integer userId, Integer videoId);
}
